#ifndef _SINGLETEMPLATE_H_
#define _SINGLETEMPLATE_H_
#include <thread>
#include <mutex>

template <typename T>
class singleton
{
public:
  static T* GetInstance()//static 不能使用普通变量
  {
    std::lock_guard<std::mutex> lcok(m);
    if(p == nullptr)
    {
      p = new T();
    }
    return p;
  }

  void Release()
  {
    delete p;
  }
  
protected:
  singleton(){}
  static T *p;
  static std::mutex m;
};

template <typename T>
T* singleton<T>::p = nullptr;
template <typename T>
std::mutex singleton<T>::m = std::mutex();

#endif